define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	
	var Model = function(){
		this.callParent();
	};

	Model.prototype.modelLoad = function(event){
		var user = localStorage.getItem("username");
		//debugger;
		this.comp("treeViewData").set({"rootFilter": "fNodeId='" + user + "'"});
		this.comp("windowDialogAddOrEdit").open();
	};

	Model.prototype.treeViewDataIndexChanged = function(event){
		switch(event.row.val("fTableName")){
			case "project_name_table":
				this.comp("buttonAdd").set({"label":"添加工程"});
			break;
			case "equip_table":
				this.comp("buttonAdd").set({"label":"添加设备"});
			break;
			case "gateway_table":
				this.comp("buttonAdd").set({"label":"添加网关"});
			break;
			case "real_data_table":
				this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			case "visual_data_table":
				this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			default:
				this.comp("buttonAdd").set({"label":event.row.val("fTableName")});
			break;
		}
		//debugger;
	};

	Model.prototype.buttonDeleteClick = function(event){
		var id = event.row.val("fNodeID")
		debugger;
		switch(event.row.val("fTableName")){
			case "project_name_table":
				//this.comp("projectData").deleteData(this.comp("projectData").find([], [], true)[0], options)
				//windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/projectEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加工程"});
			break;
			case "equip_table":
				//windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/equipEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加设备"});
			break;
			case "gateway_table":
				//windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/gatewayEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加网关"});
			break;
			case "real_data_table":
				//windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/realdataEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			case "visual_data_table":
				//windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/realdataEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			default:
				//this.comp("buttonAdd").set({"label":event.row.val("fTableName")});
			return;
		}

	};

	Model.prototype.buttonEditClick = function(event){
		//debugger;
		var windowsDialog = this.comp("windowDialogAddOrEdit");
		var row = event.bindingContext.$object;
		switch(row.val("fTableName")){
			case "project_name_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/projectEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加工程"});
			break;
			case "equip_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/equipEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加设备"});
			break;
			case "gateway_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/gatewayEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加网关"});
			break;
			case "real_data_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/realdataEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			case "visual_data_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/visualdataEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			default:
				//this.comp("buttonAdd").set({"label":event.row.val("fTableName")});
			return;
		}
		//debugger;
		//windowsDialog.update();//.doUpdate();
		windowsDialog.open({"data":{"operation":"edit", "id":row.val("fNodeId"), "parentId" : row.val("fParentID")}});

	};

	Model.prototype.buttonAddClick = function(event){
		var windowsDialog = this.comp("windowDialogAddOrEdit");
		var row = event.bindingContext.$object;
		switch(this.comp("treeViewData").getValue("fTableName")){
			case "project_name_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/projectEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加工程"});
			break;
			case "equip_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/equipEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加设备"});
			break;
			case "gateway_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/gatewayEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加网关"});
			break;
			case "real_data_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/realdataEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			case "visual_data_table":
				windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/realdataEditActivity.w");
				//this.comp("buttonAdd").set({"label":"添加采集数据"});
			break;
			default:
				//this.comp("buttonAdd").set({"label":event.row.val("fTableName")});
			return;
		}
		//windowsDialog.update();
		windowsDialog.open({"data":{"operation":"new", "id":this.comp("treeViewData").getValue("fNodeId"), "parentId" : this.comp("treeViewData").getValue("fParentID")}});
	};

	Model.prototype.buttonAddVisualClick = function(event){
		var windowsDialog = this.comp("windowDialogAddOrEdit");
		windowsDialog.src = require.toUrl("$UI/highde/modbusItems/setting/visualdataEditActivity.w");
		windowsDialog.open({"data":{"operation":"new", "id":row.val("fNodeId"), "parentId" : row.val("fParentID")}});

	};

	return Model;
});